{% extends "base.html" %}

{% block title %}Groups{% endblock %}

{% block groups %}
<ul>
{% for entry in data %}
  <li><a href="#{{entry['name'].title()}}">{{entry['name'].title()}}</a></li>
{% endfor %}
</ul>
{% endblock %}
{% block markets %}
<ul>
{% for entry in data %}
  <li><a href="#{{entry['name'].title()}}">{{entry['name'].title()}}</a></li>
{% endfor %}
</ul>
{% endblock %}

{% block content %}
    <article id="main" class="markdown-section">
	<h1>Group profiles</h1>
        {% for entry in data %}
            {% if type == "groups" %}
            <h3 id="{{entry['name'].title()}}"> <a href="/group/{{entry['name']}}">{{entry['name'].title()}}</a></h3>
            {% else %}
            <h3 id="{{entry['name'].title()}}"> <a href="/market/{{entry['name']}}">{{entry['name'].title()}}</a></h3>
            {% endif %}
            {% if entry['meta'] is not none %}  
            <h4>Description</h4>
            <p>{{ entry['meta'] }}</p>
            {% endif %}
            {% if entry['name'].lower() in parser %}
            <p><em>parsing : <code>enabled</code></em></p>
            {% endif %}
            <h4>Links</h4>
            <div class="table-responsive">
            <table id="table" class="table" style="display:table; table-layout:auto; width:100%">
            <thead>
                <tr>
                    <th style="width:25%"> Page title </th>
                    <th style="width:5%"> Available </th>
                    <th style="width:10%"> Last visit</th>
                    <th style="width:50%"> URL </th>
                    <th style="width:10%"> Screen </th>
                </tr>
            </thead>
            <tbody>
            {% for location in entry['locations'] %}
              {% if current_user.is_authenticated or not 'private' in location or location['private'] is false %}
                <tr>
                <td> {{ location['title'] }}  </td>
                {% if location['available'] is true %} <td><center> ⬆️ </center></td>
                {% else %} <td><center> ⬇️ </center></td>
                {% endif %}
                <td><center> {{ location['lastscrape'].split(' ')[0] }} </center></td>
                <td> {{location['slug']}} </td>
                {% if 'screen' in location %}
                <td><a href="{{ location['screen'] }}" rel="noopener noreferrer" target="_blank"">Screen</a></td>
                {% else %}
                <td> </td>
                {% endif %}
                </tr>
              {% endif %}
            {% endfor %}
           </tbody>
           </table>
           </div>
            {% if entry['posts'] %}
            <h4>Posts</h4>
            <div class="table-responsive">
            <table id="table" class="table" style="display:table; table-layout:auto; width:100%">
            <thead>
                <tr>
                    <th>Title</th>
                    <th style="width:10%">Date</th>
                    <th style="width:10%">Screen</th>
                </tr>
            </thead>
            <tbody>
                {% for post in entry['posts'] %}
                    <tr><td> {{post['post_title']}} </td>
                        <td><center> {{post['discovered'].split(' ')[0]}} </center></td>
                        {% if 'screen' in post and post['screen'] is not none %}
                            <td><a href="{{ post['screen'] }}" rel="noopener noreferrer" target="_blank"">Screen</a></td>
                        {% else %}
                            <td> </td>
                        {% endif %}
                    </tr>
                {% endfor %}
            </tbody>
            </table>
            </div>
            {% endif %}
        {% endfor %}
    </article>
{% endblock %}
